package com.lankystar.sos.dao.impl;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.lankystar.sos.dao.IUserLocationDao;
import com.lankystar.sos.model.UserLocation;

@Repository
public class UserLocationDaoImpl implements IUserLocationDao {

	@Autowired
	private SessionFactory sf;
	
	public Session getSession(){
		System.out.println("userLocation开启session！！");
		return sf.getCurrentSession();
	}
	@Override
	public void addUserLocation(UserLocation record) {
		getSession().save(record);

	}
	@Override
	public void updateUserLocation(UserLocation record) {
		getSession().update(record);
		
	}
	@Override
	public Object[] selectUserLocationByUserId(Integer userId) {
		String sql = "from UserLocation ul right join ul.user u where u.userId="+userId+"";
		Object[] ob = (Object[]) getSession().createQuery(sql).uniqueResult();
		return ob;
	}
	
	@Override
	public Object[] selectUserLocationByuserPhone(String userPhone) {
		String sql = "from UserLocation ul right join ul.user u where u.userPhone="+userPhone+"";
		Object[] ob = (Object[]) getSession().createQuery(sql).uniqueResult();
		return ob;
	}
	@Override
	public UserLocation selectUserLocationByuserId(Integer userId) {
		String sql = "select ul from UserLocation ul right join ul.user u where u.userId="+userId+"";
		UserLocation userLocation = (UserLocation) getSession().createQuery(sql).uniqueResult();
		return userLocation;
	}

}
